package com.atguigu.pratice;

class Ticket implements Runnable{
    private int num=50;
    public void run(){
        for (int i = 0; i < 50; i++) {
            if(num>0){

                System.out.println(Thread.currentThread().getName()+"卖出了"+(num--)+"张票,还剩"+num+"张票");
                //线程睡眠几秒
//        try {
//            TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}


            }

        }
    }
}

public class SaleTicketDemo {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();

            Thread t1 = new Thread(ticket);
            t1.start();
            Thread t2 = new Thread(ticket);
            t2.start();
            Thread t3 = new Thread(ticket);
            t3.start();




        //三个线程卖票 50张票
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i < 50; i++) {
//                    ticket.sale();
//                }
//            }
//        }).start();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i < 50; i++) {
//                    ticket.sale();
//                }
//            }
//        }).start();
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i < 50; i++) {
//                    ticket.sale();
//                }
//            }
//        }).start();
    }


}
